import request from "@/utils/request";
// import { updateStorage } from "@/utils";
export default {
  // namespaced: true,
  state: {
    datas: [],
    selet: [],
  },
  getters: {},
  mutations: {
    check(state, payload) {
      state.selet = payload.map((item) => {
        console.log(item.id);
        return item.id;
      });
      console.log(state.selet);
    },
    list(state, data) {
      state.datas = data;
    },
  },
  actions: {
    async getData(context) {
      await request.get("/users/all").then((res) => {
        // console.log(res.data.ret.data);
        // context.datas = res.data.ret.data;
        context.commit("list", res.data.ret.data);
        // console.log(state.datas);
      });
    },
    async handleDelete(context) {
      console.log(context.state.selet);
      await request.delete("/users/delete", {
        data: { id: context.state.selet },
      });
      // console.log('删除');
      console.log(context);
      context.dispatch("getData");
    },
    async alter(context, payload) {
      await request
        .put("/users/update", {
          id: payload.id,
          username: payload.username,
          password: payload.password,
        })
        .then((res) => {
          console.log(res);
        });
      context.dispatch("getData");
    },
    async all(context,payload){
      await request.post('/users/select',{
        username :  payload
      }).then(({data})=>{
        if(data.ret.length!=0){
          return 1
          // console.log('ture');
        }else{
          // console.log('false');
          return 0
        }
      })
    }
  },
};
